import request from '@/utils/request'
import { AxiosResData } from '../../common_type'
import type { User, UserResponseData, AllRoleResponseData, SetRoleData } from './type'

enum API {
  //获取全部已有用户账号信息
  ALLUSER_URL = '/admin/acl/user/',
  //添加一个新的用户账号
  ADDUSER_URL = '/admin/acl/user/save',
  //更新已有的用户账号
  UPDATEUSER_URL = '/admin/acl/user/update',
  //获取全部职位,当前账号拥有的职位接口
  ALLROLEURL = '/admin/acl/user/toAssign/',
  //给已有的用户分配角色接口
  SETROLE_URL = '/admin/acl/user/doAssignRole',
  //删除某一个账号
  DELETEUSER_URL = '/admin/acl/user/remove/',
  //批量删除的接口
  DELETEALLUSER_URL = '/admin/acl/user/batchRemove'
}

//获取用户账号信息的接口
export const reqUserInfo = (page: number, limit: number, username: string) => request.get<any, AxiosResData<UserResponseData>>(API.ALLUSER_URL + `${page}/${limit}/?username=${username}`)
// 添加用户
export const addUser = (data: User) => request.post<any, any>(API.ADDUSER_URL, data)
// 编辑用户
export const updateUser = (data: User) => request.put<any, any>(API.UPDATEUSER_URL, data)
//删除某一个账号的信息
export const reqRemoveUser = (userId: number) => request.delete<any, any>(API.DELETEUSER_URL + userId)
//批量删除的接口
export const reqDeleteMoreUser = (idList: number[]) => request.delete(API.DELETEALLUSER_URL, { data: idList })
//获取全部职位以及包含当前用户的已有的职位
export const reqAllRole = (userId: number) => request.get<any, AxiosResData<AllRoleResponseData>>(API.ALLROLEURL + userId)
// 保存分配职位
export const reqSetUserRole = (data: SetRoleData) => request.post<any, any>(API.SETROLE_URL, data)
